<?php

namespace app\admin\model\hd\activity;

use think\Model;


class Log extends Model
{





    // 表名
    protected $name = 'hd_activity_log';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'vote_results_text',
        'registration_results_text',
        'sign_text',
        'create_time_text',
        'update_time_text',
        'info',
        'user'
    ];



    public function getVoteResultsList()
    {
        return ['0' => __('弃权票'), '1' => __('同意票'), '2' => __('反对票')];
    }

    public function getRegistrationResultsList()
    {
        return ['1' => __('Registration_results 1'), '2' => __('Registration_results 2')];
    }

    public function getSignList()
    {
        return ['0' => __('Sign 0'), '1' => __('Sign 1')];
    }


    public function getVoteResultsTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['vote_results']) ? $data['vote_results'] : '');
        $list = $this->getVoteResultsList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRegistrationResultsTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['registration_results']) ? $data['registration_results'] : '');
        $list = $this->getRegistrationResultsList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSignTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sign']) ? $data['sign'] : '');
        $list = $this->getSignList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
    public function info()
    {
        return $this->belongsTo('app\admin\model\hd\activity\Info', 'act_id', 'id')->setEagerlyType(0);
    }
    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id')->setEagerlyType(0);
    }
}
